<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\captcha\Captcha;
use yii\widgets\ActiveForm;
use frontend\models\operate\User;
$this->title = '问答详情';
    $session = yii::$app->session;
    $user_id = $session->get('user_id');
    if(empty($user_id))
    {
        $this->redirect(array('/site/index'));
    }    
?>
<link rel="stylesheet" href="/static/css/public-same.css" />
<link rel="stylesheet" href="/static/css/question.css" />
<style>
    .iPhone-num .ipt {
    float: left;
    padding: 10px;
    width: 100px;
}
</style>
<?= Html::jsFile('/ueditor/ueditor.config.js')?>
<?= Html::jsFile('/ueditor/_examples/editor_api.js')?>
<!-- block-nav-banner -->
<div class="block-nav-banner">
<div class="container">
<ul class="list-inline zy-list-inline">
<li class="active"><a href="<?= Url::to(['questions/index'])?>">问答</a></li>
<li><a href="<?= Url::to(['questions/release'])?>">发布问题</a></li>
</ul>
</div>
</div>




<!-- main-area -->
<div class="main-area QA-area" style=" background: #f5f5f5;">
<div class="container">
<div class="column-layout">
<!-- main-area-left start  -->
<div class="column-col main-area-left">
                <div class="main-area-leftin">
                    <!-- 面包屑 -->
                    <ol class="breadcrumb">
                        <li><a href="<?= Url::to(['questions/index'])?>">问答</a></li>
                        <li class="active">问答详情</li>
                    </ol>
                    <!-- 正文 -->
                    <div class="QA-text-box" style="word-break: break-all">
                        <h1><?= Html::encode($data['ques_name'])?></h1>
                        <div class="QA-text-about">
                            <div class="col-left">
                                <div class="u-photo-box">
                        <a href="javascript:void(0);" target="_blank" id="40843" class="u-photo u-photo-btn">
                            <img src="http://files.bwphp.com/file/image/show/50/50?path=<?= Html::encode($data['user_thumb'])?>" alt="" height="50" width="50">
                        </a>
                        
                        <i class="ico ico-umark-2"></i>
                        
                    </div>
                                    <span class="u-name"><?= Html::encode($data['user_name'])?></span>
                                <span class="u-datetime">
                                    <?php  
                        $dur = time()-$data['ques_addtime'];
                        /*暂时没想到怎么做、先做成这样的*/
                        if($dur<60){
                            echo $dur."秒前";
                        }else{
                            if($dur<3600){
                                echo floor($dur/60)."分钟前";
                            }else{
                                if($dur<86400){
                                    echo floor($dur/3600)."小时前";
                                }else{
                                    if($dur<604800){
                                        echo floor($dur/86400)."天前";
                                    }else{
                                        if($dur<2592000){
                                            echo floor($dur/604800)."周前";
                                        }else{
                                            if($dur<31104000){
                                                echo floor($dur/2592000)."月前";
                                            }else{
                                                if($dur>31104000){
                                                    echo floor($dur/31104000)."年前";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        echo $year;
                    ?>
                                </span>
                                <span class="hot-tag-group">
                                    
                                    <a href="javascript:void(0);" class="hot-tag" target="_blank"><?= Html::encode($data['queslabel_name'])?></a>
                                    
                                    
                                    
                                

                            </span></div>
                        </div>
                    <br>
                    
                        <div class="QA-text-main" id="ask_content" style="word-break:break-all"><p style="line-height: 3em; white-space: normal; text-indent: 2em;"><span style="font-size: 16px;">
                            <?= Html::encodejavascript($data['ques_content'])?>
                        </span></p><p><br> </p></div>
                    
                        <div class="QA-text-foot">
                            <div class="col-left">

                                <span class="fun-btn" style="cursor: auto;">
                                    <!-- <i class="ico ico-share"></i> -->
                                    <span class="ico-label-text" style="vertical-align: top; font-size:18px">分享到:
                                        <div class="bshare-custom icon-medium-plus">
                                            <a class="bshare-weixin" data-cnd="weixin" title="分享到微信"></a>

                                            <a title="分享到QQ空间" class="bshare-qzone"></a>

                                            <a title="分享到新浪微博" class="bshare-sinaminiblog"></a>

                                            <a title="更多平台" class="bshare-more bshare-more-icon more-style-addthis"></a>

                                            </div>

                                            <script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/buttonLite.js#style=-1&amp;uuid=&amp;pophcol=2&amp;lang=zh"></script>
                                            <script type="text/javascript" charset="utf-8" src="http://static.bshare.cn/b/bshareC0.js"></script>
                                    </span>
                                </span>
                                
                                
                            </div>
                            <div class="col-right">

                                

                                <span class="fun-btn u-collect">
                                    <span class="ico-label-text collect" style='font-size:16px' id="<?= Html::encode($data['ques_id'])?>">收藏</span>
                                </span>

                                
                                

                                
                            </div>
                        </div>
                    </div>
                    <!-- 评论 -->
                    <div class="ibox">
                        <div class="ibox-head" style="border-bottom: 1px solid #ececec;">
                            <div class="ibox-tit-text"><!-- <span id="comment_count">9</span>条 -->回答</div>
                        </div>
                        <div class="ibox-body">
                            <div class="comment-list">
                                <!-- reply  -->
                                
            <div style="" class="item reply-box">
                <div class="col-left">
                    <div class="col-in">  
                        <div class="u-photo-box">
                            <a href="<?= Url::to(['center/index'])?>" class="u-photo" id="73826">
                                <img src="http://files.bwphp.com/file/image/show/50/50?path=<?= Html::encode($user['user_thumb'])?>" alt="" height="50" width="50">
                                
                            </a>
                            <p><?= Html::encode($user['user_name'])?></p>
                        </div> 
                    </div>
                </div>
                <div style="" class="col-right">
                    <div style="" class="col-in comm-reply-box comment-input">
                        <div class="edui-default" id="comment1" style="width: 100%;">
                        <?php $form = ActiveForm::begin([
                                'action' => ['questions/reply'],
                                'method'=>'post',
                        ])?>
                        <textarea style="width: 100%; height: 100px;padding: 10px;" name="answer_content" id="myEditor" placeholder="发表回答"></textarea>
                        <div class="comm-reply-foot">
                        <?= $form->field($model, 'verifyCode', [
                                'options' => ['class' => ''],
                            ])->widget(Captcha::className(),[
                               'template' => '<p class="iPhone-num">{image}<span class="img-num">{input}</span></p>',
                               'imageOptions' => ['alt' => '验证码'],
                               'captchaAction' => 'questions/captcha',
                               'options' =>['placeholder' => '请输入验证码', 'class' => 'ipt'],
                            ]); ?>
                            <input type="hidden" name="ques_id" value="<?= Html::encode($data['ques_id'])?>">
                            <input id="main-reply" class="btn btn-micv5 btn-lg-fts reply" parent_id="0" value="回答"  type="submit">
                            &nbsp; &nbsp;<span style="color:red;display:none;">至少3个字</span>
                        
                        
                        </div>
                        <?php $form = ActiveForm::end()?>
                                            
                        </div>
                    </div>
                </div>
                   
                
            </div>
            
        </div>
    </div>
                        <div class="ibox-body zy_comment">
                            <div class="comment-list">
                                <!-- item  -->
                                <div id="comments">
                                    <!--这里放异步加载的评论内容-->
        <!-- 评论开始 -->
        <?php foreach ($release as $key => $reply) {?>                            
        <div class="item">
    <div class="col-left">
        <div class="col-in">
            <div class="u-photo-box">
                <a href="javescript:void(0);" target="_blank" class="u-photo u-photo-btn" id="67912">
                    <img width="50" height="50" src="http://files.bwphp.com/file/image/show/50/50?path=<?= Html::encode($reply['user_thumb'])?>" alt="">
                </a>
                
            </div>
            <div class="text-center">
                
            </div>
        </div>
    </div>
    <div class="col-right">
        <div class="col-in comm-main">
            <div class="comm-about">
                <span class="u-name"><?= Html::encode($reply['user_name'])?><!-- <span class="u-status">老师</span> --></span>
                <span class="u-datetime">
                    <?php  
                        $dur = time()-$reply['answer_addtime'];
                        /*暂时没想到怎么做、先做成这样的*/
                        if($dur<60){
                            echo $dur."秒前";
                        }else{
                            if($dur<3600){
                                echo floor($dur/60)."分钟前";
                            }else{
                                if($dur<86400){
                                    echo floor($dur/3600)."小时前";
                                }else{
                                    if($dur<604800){
                                        echo floor($dur/86400)."天前";
                                    }else{
                                        if($dur<2592000){
                                            echo floor($dur/604800)."周前";
                                        }else{
                                            if($dur<31104000){
                                                echo floor($dur/2592000)."月前";
                                            }else{
                                                if($dur>31104000){
                                                    echo floor($dur/31104000)."年前";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        echo $year;
                    ?>
                </span>
                <?php if($reply['answer_best']==1){?>
                <span style="float:right">最佳</span>
                <?php }?>
            </div>
            <div class="comm-cnt zy_shou11" style="max-width: 693px; word-break:break-all">
                <p><?= Html::encodejavascript($reply['answer_content'])?></p><!--<p>查看更多</p>-->
            </div>
            <div class="comm-fun">
                <span class="fun-btn comm-reply-btn" parent_id="30011" target_box="reply-box-30011" child_id="30011" u_name="O桑"><!-- 回复 --></span>
                <span class="fun-btn praise-btn ">
                    <i class="ico ico-good"></i>
                    <span class="ico-label-text"><!-- 0 --></span>
                </span>
            </div>
        </div>
        
        
        
        
        
        
    </div>
</div>
<?php }?>
<!-- 评论结束 -->
     
                                </div>
                            </div>
                            <!-- <p style="cursor: pointer;" id="load_message" class="text-center no-message">加载更多评论</p> -->
                            <input value="10" id="loadmore_page" hidden="hidden">
                        </div>
                    </div>
                </div>
            </div>
<!-- main-area-left end  -->
<!-- main-area-right start  -->
<?php echo $this->render('common')?>
<!-- main-area-right end  -->
</div>
</div>
</div>
</div>
<div class="modal fade" id="likeTwice" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm" style="top:150px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" style="font-size: 18px;">消息提示</h4>
            </div>
            <div class="modal-body">
                <section class="box-login v5-input-txt" id="box-login">
                        <center><h4 style="font-size: 18px;margin-bottom: 20px;">您已收藏，不能再收藏了！</h4>
                        <button data-dismiss="modal"  style="width: 150px;" type="button" class="btn btn-micv5 btn-block">确定</button></center>
                        
                </section>
            </div>
        </div>
    </div>
</div>
<script>
    /*编辑器*/
    var ue = UE.getEditor('myEditor');
    //收藏
    $(document).on('click','.collect',function(){
        var id = $(this).attr('id');
        $.ajax({
            type : "get",
            url : "<?php echo Url::to(['questions/collect']);?>",
            data : 'id='+id,
            dataType : 'json',
            success: function(msg){
                if(msg.code == 1){
                    jq('#loginModal').modal('show');
                }else if(msg.code == 2){
                    //不能重复喜欢
                    jq('#likeTwice').modal('show');
                }else if(msg.code == 3){
                    //喜欢成功
                    //thiss.replaceWith()
                    alert(msg.msg)
                }else if(msg.code == 4){
                    alert(msg.msg)
                }
            }
        });
    })
</script>